﻿// 物体基类

using QuadTree;
using Unity.Mathematics;
using UnityEngine;

public abstract class ObjectScene : ObjectBase, ICollisionCore
{



    #region 表现相关

    GameObject m_SharpNode;
    // 主角的表现
    public GameObject SharpNode
    {
        set { m_SharpNode = value; }
        get
        {
            if (m_SharpNode == null)
                m_SharpNode = GetSharpNode();
            return m_SharpNode;
        }
    }

    protected virtual GameObject GetSharpNode()
    {
        return gameObject;
    }
    public void LookAt(Vector2 pos)
    {
        GetSharpNode().FaceVector2(pos);
    }
    GameObject m_LogicNode;
    public GameObject LogicNode
    {
        set { m_LogicNode = value; }
        get
        {
            if (m_LogicNode == null)
                m_LogicNode = gameObject;
            return m_LogicNode;
        }
    }

    // 动画
    Animator m_Animator;
    public Animator Animator
    {
        get
        {
            if (m_Animator == null)
                m_Animator = SharpNode.GetComponent<Animator>();
            return m_Animator;
        }

    }
    /// <summary>
    /// 播放东海
    /// </summary>
    /// <param name="str"></param>
    /// <param name="fSpeed"></param>
    public void DoPlayAnim(string str, float fSpeed = 1)
    {
        if (Animator != null)
        {
            Animator.speed = fSpeed;
            Animator.SetTrigger(str);
        }
    }
    #endregion

    public virtual void DoEnterGame()
    {

    }
    public virtual void DoEnterGame(Vector3 pos, Vector3 dir)
    {

    }
    public virtual void DoEnterGame(Vector3 pos, float angel)
    {

    }
    public virtual void DoExitGame()
    {

    }


    public Vector2 GetPositon()
    {
        return SharpNode.transform.position;
    }
    public virtual void SetPosition(Vector2 pos)
    {
        SharpNode.transform.position = (Vector3)pos;
    }

    public void AddPosition(Vector2 pos)
    {
        SharpNode.transform.position += (Vector3)pos;
    }
    public virtual void SetFace(Vector3 dir)
    {
        SharpNode.transform.localRotation = Quaternion.LookRotation(dir);

    }
    public virtual void SetFace(float angel)
    {
        SharpNode.transform.localRotation = Quaternion.Euler(0, 0, angel);
    }
    public enum EFaceDir
    {
        None,
        Left,
        Right,
        Up,
        Down
    }
    EFaceDir m_FaceDir;
    public EFaceDir FaceDir
    {
        get
        {
            return m_FaceDir;
        }
    }

    public virtual void Trun(EFaceDir dir)
    {
        m_FaceDir = dir;
    }

    public virtual float GetRadius()
    {
        return 1;
    }
    public virtual void SetRadius(float radius)
    {

    }
    #region 索敌逻辑
    float3 ICollisionCore.m_Center { get => (Vector3)GetPositon(); set => SetPosition((Vector3)value); }

    #endregion
}
